//
//  CurrentOrderTest.m
//  Reservation
//
//  Created by Wai Man Chan on 5/3/14.
//  Copyright (c) 2014 CHAN, Wai Man. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "CurrentOrderModel.h"
#import <CoreLocation/CoreLocation.h>

@interface CurrentOrderModel ()
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region;
@end

@interface testBeacon : CLBeacon
@end
@implementation testBeacon
- (NSInteger)rssi { return -10; }
@end

@interface testBeacon2 : CLBeacon
@end
@implementation testBeacon2
- (NSInteger)rssi { return -9; }
@end

@interface CurrentOrderTest : XCTestCase {
    CurrentOrderModel *model;
}
@end

@implementation CurrentOrderTest

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    model = [CurrentOrderModel shareModel];
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testEmptyBeacon {
    [model locationManager:NULL didRangeBeacons:@[] inRegion:NULL];
    XCTAssertFalse(model.found, @"Found ghost beacon");
}

- (void)testWithOneBeacon {
    CLBeacon *beacon = [[testBeacon alloc] init];
    [model locationManager:NULL didRangeBeacons:@[beacon] inRegion:NULL];
    XCTAssertTrue(model.found, @"Found ghost beacon");
}

- (void)testWithOneBeaconChange {
    CLBeacon *beacon = [[testBeacon alloc] init];
    [model locationManager:NULL didRangeBeacons:@[beacon] inRegion:NULL];
    beacon = [[testBeacon2 alloc] init];
    [model locationManager:NULL didRangeBeacons:@[beacon] inRegion:NULL];
    XCTAssertTrue(model.found, @"Found ghost beacon");
}

- (void)testWithRemoveBeacon {
    CLBeacon *beacon = [[testBeacon alloc] init];
    [model locationManager:NULL didRangeBeacons:@[beacon] inRegion:NULL];
    [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    [model locationManager:NULL didRangeBeacons:@[] inRegion:NULL];
    XCTAssertFalse(model.found, @"Found ghost beacon");
}

@end
